% -*-coding: utf-8 -*-
% File: setup/format.tex
%
% 修改自: PlutoThesis_UTF8_1.9.4.20100419.zip
%         http://code.google.com/p/plutothesis/
%
% 修改记录: Yuliang <jyl198803@gmail.com> 2010-05-23
%     设计哈工程本科毕业论文规范
% 修改记录: Yuliang <jyl198803@gmail.com> 2010-05-24
%     设计哈工程本科毕业论文规范
% 修改记录: Yuliang <jyl198803@gmail.com> 2010-05-25
%     设计哈工程本科毕业论文规范
%
% 注: 标注 TODO 的是未测试的内容，或者计划将来完成的内容；
%     目前专门针对 Linux 进行修改，由于论文规范的字体要求，使用 Windows 的盗版字体;
%

% XXX 哈工程本科论文规定(详见 setup/package.tex 文件中 引入 geometry 时的说明):
%   论文大小为 140mm*212mm，包括页眉页脚则为 140mm*226mm
%   页码在页脚居中放置；
%%% 由于使用了 geometry 宏包解决版面问题，因此这里不再单独设定下面的参数
%% 左右
%\setlength{\textwidth}{15cm}
%\setlength{\oddsidemargin}{0.46cm}   % 左边 3cm=0.46+2.54
%\setlength{\evensidemargin}{0.46cm}
%% 上下
%\setlength{\topmargin}{0.42cm}       % 3.3=2.54+0.76
%\setlength{\headheight}{0.80cm}      % 0.8
%\setlength{\headsep}{0.40cm}         % 0.4
%\setlength{\textheight}{22.0cm}      % 22.0
%\setlength{\footskip}{1.1cm}         %1.1

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  允许公式换页显示,否则大型推导公式都在一页内，一页显示不下放到第二页，
%  导致很大的空白空间，很不好看
\allowdisplaybreaks[4]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  下面这组命令使浮动对象的缺省值稍微宽松一点，从而防止浮动对象占据过多的
%  文本页面，也可以防止在很大空白的浮动页上放置很小的图形。
\renewcommand{\topfraction}{0.9999999}
\renewcommand{\textfraction}{0.0000001}
\renewcommand{\floatpagefraction}{0.9999}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  重定义一些正文相关标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\theoremstyle{plain} \theorembodyfont{\song\rmfamily}
\theoremheaderfont{\hei\rmfamily} %\theoremseparator{:}
\newtheorem{definition}{\hei 定义}[chapter]
\newtheorem{example}{\hei 例}[chapter]
\newtheorem{algo}{\hei 算法}[chapter]
\newtheorem{theorem}{\hei 定理}[chapter]
\newtheorem{axiom}{\hei 公理}[chapter]
\newtheorem{proposition}{\hei 命题}[chapter]
\newtheorem{lemma}{\hei 引理}[chapter]
\newtheorem{corollary}{\hei 推论}[chapter]
\newtheorem{remark}{\hei 注解}[chapter]
%\newtheorem{proposition}[definition]{\hei 命题}
%\newtheorem{lemma}[definition]{\hei 引理}
%\newtheorem{exercise}[definition]{}
%\newtheorem{corollary}[definition]{\hei 推论}
%\newtheorem{remark}[definition]{\hei 注解}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  解决原 proof 定理环境的两个问题：
%    1. proof 中的 item 缩进不对
%    2. proof 中的最后一个公式下出现一个黑方块
%  \theoremsymbol{$\blacksquare$}
%  \newtheorem{proof}{\hei 证明}
\newenvironment{proof}{\noindent{\hei 证明：}}{\hfill $ \square $ \vskip 4mm}
\theoremsymbol{$\square$}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 用于中文段落缩进和正文版式
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifx\atempxetex\usewhat
\newcommand{\CJKcaption}[1]{
  \ifx\CJK@actualBinding \@empty
    \PackageError{CJK}{
      You must be inside of a CJK environment to use \protect\CJKcaption}{}
  \else
    \makeatletter
    \InputIfFileExists{#1.cpx}{}{
      \PackageError{CJK}{
        Can't find #1.cpx}{
        The default captions are used if you continue.}}
    \makeatother
  \fi}
\CJKcaption{gb_452_UTF8}
\else
\CJKcaption{gb_452_UTF8}
\newlength \CJKtwospaces
\def\CJKindent{
    \settowidth\CJKtwospaces{\CJKchar{"0A1}{"0A1}\CJKchar{"0A1}{"0A1}}%
    \parindent\CJKtwospaces
}
%\CJKtilde  % 使 ~ 符号表示一个可换行的空格 %\CJKindent 设置除首段外每段开头空两格，与 indentfirst 包搭配可以使首段也空两格
\fi

%\setlength{\parindent}{26pt}  % 由于工大论文的每行的字距加大了，需要增加段首缩 2pt；至少在 xelatex 方式下已经不起作用

% 四个 ~ 代表两格汉字的距离
\renewcommand\contentsname{\hei 目~~~~~~~~录}

% 章节标题为"第1章"的形式
\renewcommand\chaptername{\CJKprechaptername~\thechapter~\CJKchaptername}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%定义段落章节的标题和目录项的格式
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setcounter{secnumdepth}{4} \setcounter{tocdepth}{2}

% \titleformat 和 \titlespacing 是 titlesec 宏包定义的
%
% 章节标题: XXX 哈工程本科论文规定: 
%     章标题: 小二黑体(衬线体) 居中对齐
%     节标题: 四号黑体(衬线体) 不知道是不是"悬挂的居中对齐"，反正就是在左侧，hang 就行
%
% block 为居中对齐，hang 为悬挂的居中对齐
\titleformat{\chapter}[block]{\xiaoer\sf\hei\filcenter\boldmath}{\xiaoer\chaptertitlename}{18pt}{\xiaoer}
\titleformat{\section}[hang]{\sf\hei\sihao\boldmath}{\xiaosan\thesection}{0.5em}{}
\titleformat{\subsection}[hang]{\sf\hei\sihao\boldmath}{\sihao\thesubsection}{0.5em}{}
\titleformat{\subsubsection}[hang]{\sf\hei\sihao\boldmath}{\thesubsubsection}{0.5em}{}

% 章节前后的间距细调，
%
% 章节标题: XXX 哈工程本科论文规定: 
%     章的段前为 0.8 行，段后 0.5 行；
%     节、条的段前为 0.5 行，段后 0.5 行；
%   经过与现行 Word 模板对比，采用下面值
%     节字号为四号，14pt，则左、上、下应为 {0pt}{7pt}{7pt}
%     章字号为小二，22pt，则左、上、下应为 {0pt}{17.6pt}{11pt}
%     但上本身已经有距离了(TODO: 究竟是什么距离涅?，猜测跟 titlesec 宏包有关)，故试验之，还需要一些调整，不很精确，但很象
%     小节和小小节同上
\titlespacing{\chapter}{0pt}{0pt}{11pt}
\titlespacing{\section}{0pt}{-1pt}{7pt}
\titlespacing{\subsection}{0pt}{-1pt}{7pt}
\titlespacing{\subsubsection}{0pt}{-1pt}{7pt}

% 设置目录中各级标题之间的缩进
% 目录: XXX 哈工程本科论文规定:
%   其实论文规范没有规定缩进距离，只规定见附件，而附件印刷错误，因此这里依照现行 Word 模板规定
%     1、目录中，每两个相邻级别目录之间，低级别目录向右缩进两个汉字字符()；
%     2、最高级目录贴紧最左侧与左边距齐平
%     3、最高级目录包括章、结论、参考文献、致谢、附录等，摘要不加入目录
%     4、最高级目录标题使用四号黑体字，其他采用小四号宋体
%     5、点号小一点，各级别目录中的页码均为小四号，数字为新罗马
%     6、格尺测量任意级别目录，上下相邻两条间距均为 4mm 左右
% TODO: 本科没有英文目录，暂无调整，Yuliang 也不知道该怎么调整
\makeatletter
\renewcommand*\l@chapter{\@dottedtocline{0}{0em}{4.84em}}  % 控制英文目录：细点为 \@dottedtocline，粗点为 \@dottedtoclinebold
\renewcommand*\l@section{\@dottedtocline{1}{12pt}{18pt}}
\renewcommand*\l@subsection{\@dottedtocline{2}{24pt}{27pt}}
\renewcommand*\l@subsubsection{\@dottedtocline{3}{36pt}{39pt}}
\renewcommand*\l@paragraph{\@dottedtocline{4}{48pt}{48pt}}
\renewcommand*\l@subparagraph{\@dottedtocline{5}{60pt}{60pt}}
% 英文目录中章标题对应的点号及相应页码为黑体
\def\@dottedtoclinebold#1#2#3#4#5{%
 \ifnum #1>\c@tocdepth \else
 \vskip \z@ \@plus.2\p@
{\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
\parindent #2\relax\@afterindenttrue
 \interlinepenalty\@M
\leavevmode
 \@tempdima #3\relax
 \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
{#4}\nobreak
 \leaders\hbox{$\m@th
\mkern \@dotsep mu\hbox{\ifnum1=#1 \bf\fi.}\mkern \@dotsep
mu$}\hfill
 \nobreak
\hb@xt@\@pnumwidth{\hfil  \normalfont \normalcolor \ifnum1=#1 \bf\fi#5}  % 目录层为1时，页码粗体
\par}%
\fi}

% XXX: 控制中文目录，请查阅 titletoc 宏包
%   命令：
%   \titlecontents{<section>}[<left>]{<above>}{<before with label>}{<before without label>}{<filler and page>}[<after>]
%   \dottedcontents{<section>}[<left>]{<above>}{<label width>}{<leader width>}
%
%   至于节以及更低级标题的设置，Yuliang 以贫乏的审美能力决定 1.8em、2.7em、3.4em 比 Word 里面的效果美观，因此没有修改；
%   这个数字(label width)决定节号例如 1.1 和节名例如"引言"之间的距离，就是把 label 往后推
%
%\titlecontents{chapter}[3.92em]{\vspace{0.5em}\hspace{-3.92em}\hei \bf\boldmath}{\contentslabel{0em}}{\hspace*{-0em}}{\normalfont\titlerule*[5pt]{.}\contentspage}
%TODO 这是工大模板使用的命令，Yuliang 不理解为什么要先把 left 设为 3.92 然后 above 里面再 \hspace{-3.92}，所以 Yuliang 先把这些去掉，希望能出现问题或者证明上面那些没有用
%     至于 \contentslabel{0em}，因为中文目录和英文不同，所以想必设为 0 是合理的，只是确切原因也不知道，还有 \hspace*{0em}，如果去掉也是可以的，毕竟是 0

\titlecontents{chapter}[0em]{\vspace{0.5em}\hei \bf\boldmath}{\contentslabel{0em}}{\hspace*{0em}}{\normalfont\titlerule*[5pt]{.}\contentspage}  % \normalfont 应该是新罗马，未试图将点点们调密，想必目录要求不会苛刻，审稿子的老师不会像传说中的那么变态
\dottedcontents{section}[1.40cm]{\vspace{0.5em}}{1.8em}{5pt}
\dottedcontents{subsection}[2.50cm]{\vspace{0.5em}}{2.7em}{5pt}
\dottedcontents{subsubsection}[3.60cm]{\vspace{0.5em}}{3.4em}{5pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  定义页眉和页脚 使用fancyhdr 宏包
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newcommand{\makeheadrule}{
%\makebox[-3pt][l]{\rule[.7\baselineskip]{\headwidth}{0.4pt}}
%\rule[0.85\baselineskip]{\headwidth}{2.25pt}\vskip-.8\baselineskip}
\newcommand{\makeheadrule}{
\vskip-.3\baselineskip\makebox[-3pt][l]{\rule[.9\baselineskip]{\headwidth}{0.4pt}}
\rule[0.65\baselineskip]{\headwidth}{2.25pt}\vskip-.8\baselineskip}

\renewcommand{\headrule}{
    {\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
     \makeheadrule}}

\pagestyle{fancyplain}

%  去掉章节标题中的数字
%  不要注销这一行，否则页眉会变成："第1章1 绪论"样式
\renewcommand{\chaptermark}[1]{\markboth{\chaptertitlename~~ \ #1}{}}
 \fancyhf{}

%  在 book 文档类别下，\leftmark 自动存录各章之章名，\rightmark 记录节标题
%  页眉字号 工程要求 五号宋体
%  根据单双面打印设置不同的页眉；
%  逻辑变量 oneortwoside 在 setup/type.tex 中定义，twoside 为 true
%  双面打印工程标准未知，暂时没什么改动
\ifoneortwoside
  \fancyhead[CO]{\song \xiaowu\leftmark}
  \fancyhead[CE]{\song \xiaowu 哈尔滨工程大学\cxueke\cxuewei 学位论文}
  \fancyfoot[C,C]{\xiaowu --~\thepage~--}
\else  % 因为变态的本科论文规范是单面的，所以单面必然会复杂
  \ifxueweibachelor  % 为变态的本科规范单独设置
    \fancyhead[CO]{\song \wuhao 哈尔滨工程大学\cxuewei 毕业论文}
    \fancyhead[CE]{\song \wuhao 哈尔滨工程大学\cxuewei 毕业论文}
    \fancyfoot[C,C]{\xiaowu ~\thepage~}
  \else  % 想必是其他要求单面打印的学位，格式没改动
    \fancyhead[CO]{\song \wuhao 哈尔滨工程大学\cxueke\cxuewei 学位论文}
    \fancyhead[CE]{\song \wuhao 哈尔滨工程大学\cxueke\cxuewei 学位论文}
    \fancyfoot[C,C]{\xiaowu --~\thepage~--}
  \fi
\fi

\renewcommand\frontmatter{
    \cleardoublepage
  \@mainmatterfalse
  \pagenumbering{Roman}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  设置行距和段落间垂直距离
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% XXX: 工大模板增大了字符间距，工程本科论文模板暂时不需要
%      由于版式设置不同，现在每行已经是 33 个字符，而且经过实际测量，字符间距与现行 Word 模板符合
% CJKoglue 是新版 CJKpunct 中的命令，以此来判断采用的是新版还是旧版 CJKpunct 宏包
%\ifx\CJKoglue\undefined  
%\renewcommand{\CJKglue}{\hskip 0.3pt plus 0.08\baselineskip} % 加大字间距，使每行33个字 
%\else
%\let\CJKglue\CJKoglue
%\renewcommand{\CJKglue}{\hskip 0.3pt plus 0.08\baselineskip} % 加大字间距，使每行33个字
%\fi

%\setlength{\belowcaptionskip}{10pt}   % 加大标题和表格之间的距离 \abovecaptionskip 默认是10pt
\setlength{\parskip}{0pt plus 2pt}  % 段间距设为 0，并且可增大的弹性距离
\renewcommand{\baselinestretch}{1.3}  % 定义行距，这里为本科规范定义的字体已经全部把行距改为 22pt 了，神奇啊；不过据说 \baselinestretch 1.3 大约就是 1.5 倍行距

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  调整列表环境的垂直间距 TODO XXX
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setitemize{itemindent=38pt,leftmargin=0pt,itemsep=-0.4ex,listparindent=26pt,partopsep=0pt,parsep=0.5ex,topsep=-0.25ex}
\setenumerate{itemindent=38pt,leftmargin=0pt,itemsep=-0.4ex,listparindent=26pt,partopsep=0pt,parsep=0.5ex,topsep=-0.25ex}
\setdescription{itemindent=38pt,leftmargin=0pt,itemsep=-0.4ex,listparindent=26pt,partopsep=0pt,parsep=0.5ex,topsep=-0.25ex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  参考文献格式 TODO XXX
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand\@biblabel[1]{[#1]\hspace{0.5em}} %参考文献里标号两边的括号
\newcommand{\ucite}[1]{$^{\mbox{\scriptsize \cite{#1}}}$} % 增加 \ucite 命令使显示的引用为上标形式
\newcommand{\citeup}[1]{$^{\mbox{\scriptsize \cite{#1}}}$} % for WinEdt users

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 定制浮动图形和表格标题样式
% 这里用 ccaption 完全代替了 caption2 的功能 TODO XXX
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\captionstyle{\centering}    % 不同的图标题形式采用不同的命令
\hangcaption
\captionnamefont{\song \rmfamily\wuhao\selectfont}
\captiontitlefont{\song \rmfamily\wuhao\selectfont}
\captiondelim{~} %~

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 定义题头格言的格式 TODO XXX
% 用法 \begin{Aphorism}{author}
%         aphorism
%      \end{Aphorism}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newsavebox{\AphorismAuthor}
\newenvironment{Aphorism}[1]
{\vspace{0.5cm}\begin{sloppypar} \slshape
\sbox{\AphorismAuthor}{#1}
\begin{quote}\small\itshape }
{\\ \hspace*{\fill}------\hspace{0.2cm} \usebox{\AphorismAuthor}
\end{quote}
\end{sloppypar}\vspace{0.5cm}}

% 自定义一个空命令，用于注释掉文本中不需要的部分。
\newcommand{\comment}[1]{}

\renewcommand\contentsname{\hei 目~~~~录}
\renewcommand\listfigurename{\hei 插~~~~图}
\renewcommand\listtablename{\hei 表~~~~格}

% 将章标题中的中文数字（一、二、三）变为阿拉伯数字(1,2,3)
\renewcommand\CJKthechapter{{\@arabic\c@chapter}}

% 不要拉大行距使得页面充满
\raggedbottom

% This is the flag for longer version
\newcommand{\longer}[2]{#1}

\newcommand{\ds}{\displaystyle}

% define graph scale
\def\gs{1.0}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 自定义项目列表标签及格式 TODO XXX
%  \begin{hitlist}
%    列表项
%  \end{hitlist}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{hitctr}  % 自定义新计数器
\newenvironment{hitlist}{  % 定义新环境
\begin{list}{{\hei (\arabic{hitctr})}}  % 标签格式
    {
     \usecounter{hitctr}
     \setlength{\leftmargin}{0cm}       % 左边界
     \setlength{\parsep}{0ex}           % 段落间距
     \setlength{\topsep}{0pt}           % 列表到上下文的垂直距离
     \setlength{\itemsep}{0ex}          % 标签间距
     \setlength{\labelsep}{0.3em}       % 标号和列表项之间的距离,默认 0.5em
     \setlength{\itemindent}{46pt}      % 标签缩进量
     \setlength{\listparindent}{27pt}   % 段落缩进量
    }}
{\end{list}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 自定义项目列表标签及格式
%  \begin{publist}
%    列表项
%  \end{publist}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{pubctr}  % 自定义新计数器
\newenvironment{publist}{  % 定义新环境
\begin{list}{\arabic{pubctr}}  % 标签格式
    {
     \usecounter{pubctr}
     \setlength{\leftmargin}{2em}      % 左边界 \leftmargin =\itemindent + \labelwidth + \labelsep
     \setlength{\itemindent}{0em}      % 标号缩进量
     \setlength{\labelwidth}{1em}      % 标号宽度
     \setlength{\labelsep}{1em}        % 标号和列表项之间的距离,默认0.5em
     \setlength{\rightmargin}{0em}     % 右边界
     \setlength{\topsep}{0ex}          % 列表到上下文的垂直距离
%     \setlength{\partopsep}{0ex}       % 列表是一个新的段落时，加的额外到上下文的距离
     \setlength{\parsep}{0ex}          % 段落间距
     \setlength{\itemsep}{0ex}         % 标签间距
     \setlength{\listparindent}{26pt}  % 段落缩进量
    }}
{\end{list}}%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  默认字体
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand\normalsize{
  \@setfontsize\normalsize{12pt}{13pt}
  \setlength\abovedisplayskip{5pt plus 2pt minus 2pt}  % by gengfazhan 
  \setlength\abovedisplayshortskip{4pt plus 2pt minus 2pt}  % by gengfazhan（生成的公式和正文距离减小了，比正常行距稍大一些）
  \setlength\belowdisplayskip{\abovedisplayskip}
  \setlength\belowdisplayshortskip{\abovedisplayshortskip}
  \setlength\jot{6pt}
  \let\@listi\@listI}
\def\defaultfont{\renewcommand{\baselinestretch}{1.5}\normalsize\selectfont}  % 正文行间距，大致与 Word 中小四宋体的 1.25 倍行距相同，使用者若不满意可精调此参数
\predisplaypenalty=0  % 公式之前可以换页，公式出现在页面顶部

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  封面、摘要、版权、致谢格式定义 TODO XXX
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\ctitle#1{\def\@ctitle{#1}}\def\@ctitle{}
\def\cdegree#1{\def\@cdegree{#1}}\def\@cdegree{}
\def\caffil#1{\def\@caffil{#1}}\def\@caffil{}
\def\csubject#1{\def\@csubject{#1}}\def\@csubject{}
\def\cauthor#1{\def\@cauthor{#1}}\def\@cauthor{}
\def\csupervisor#1{\def\@csupervisor{#1}}\def\@csupervisor{}
\def\cassosupervisor#1{\def\@cassosupervisor{~ & {\hei 副 \hfill 导 \hfill 师：} & #1\\}}\def\@cassosupervisor{}
\def\ccosupervisor#1{\def\@ccosupervisor{~ & {\hei 联 \hfill 合\hfill 导 \hfill 师：} & #1\\}}\def\@ccosupervisor{}
\def\cdate#1{\def\@cdate{#1}}\def\@cdate{}
\long\def\cabstract#1{\long\def\@cabstract{#1}}\long\def\@cabstract{}
\def\ckeywords#1{\def\@ckeywords{#1}}\def\@ckeywords{}

\def\etitle#1{\def\@etitle{#1}}\def\@etitle{}
\def\edegree#1{\def\@edegree{#1}}\def\@edegree{}
\def\eaffil#1{\def\@eaffil{#1}}\def\@eaffil{}
\def\esubject#1{\def\@esubject{#1}}\def\@esubject{}
\def\eauthor#1{\def\@eauthor{#1}}\def\@eauthor{}
\def\esupervisor#1{\def\@esupervisor{#1}}\def\@esupervisor{}
%\def\eassosupervisor#1{\def\@eassosupervisor{#1}}\def\@eassosupervisor{}
\def\eassosupervisor#1{\def\@eassosupervisor{~ & \textbf{Associate Supervisor:} & #1\\}}\def\@eassosupervisor{}
%\def\ecosupervisor#1{\def\@ecosupervisor{#1}}\def\@ecosupervisor{}
\def\ecosupervisor#1{\def\@ecosupervisor{~ & \textbf{Co Supervisor:} & #1\\}}\def\@ecosupervisor{}
\def\edate#1{\def\@edate{#1}}\def\@edate{}
\long\def\eabstract#1{\long\def\@eabstract{#1}}\long\def\@eabstract{}
\long\def\NotationList#1{\long\def\@NotationList{#1}}\long\def\@NotationList{}
\def\ekeywords#1{\def\@ekeywords{#1}}\def\@ekeywords{}
\def\natclassifiedindex#1{\def\@natclassifiedindex{#1}}\def\@natclassifiedindex{}
\def\internatclassifiedindex#1{\def\@internatclassifiedindex{#1}}\def\@internatclassifiedindex{}
\def\statesecrets#1{\def\@statesecrets{#1}}\def\@statesecrets{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  定义封面 TODO XXX
%  完全不同了，本科论文没有英文封面、英文目录，这里先考虑本科规范
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 定义学号长度，保证密级下面的横线和学号下面的横线一样长
\newlength{\lengthofxuehao}
\settowidth{\lengthofxuehao}{\xuehao}

\def\makecover{
    \normalbiao %表格字号设置
    \begin{titlepage}

    % 封面
    \begin{center}
    \parbox[t][0.8cm][t]{\textwidth}{\hei \wuhao \hfill 学~~~~~~号：\underline{\makebox[\lengthofxuehao][c]\xuehao}~~~}
    \parbox[t][0.8cm][t]{\textwidth}{\hei \wuhao \hfill 密~~~~~~级：\underline{\makebox[\lengthofxuehao][c]{}}~~~}  % \lengthofxuehao 决定了一个空横线的长度，本科论文的密级留空，即使填写，密级也比学号短，故使用学号长度
    \end{center}

    \begin{center}

    \parbox[t][1.8cm][t]{\textwidth}{
      \begin{center} \end{center}
    }

    \parbox[t][1cm][b]{\textwidth}{
      \erhao
      \begin{center}{\song 哈尔滨工程大学\cxuewei 毕业论文}\end{center}
    }

    \parbox[t][1.7cm][t]{\textwidth}{
      \begin{center} \end{center}
    }

    \parbox[t][2cm][t]{\textwidth}{
      \xiaoyi
      \begin{center}{\hei \@ctitle}\end{center}
    }

    \ifxueweidoctor  % TODO: 将来的事
    \parbox[t][3.9cm][t]{\textwidth}{
      \erhao  % 英文标题太长时可以采用\xiaoer
      \begin{center} {\bfseries  \@etitle}\end{center}
    }
    \else
    \parbox[t][3.9cm][t]{\textwidth}{
       \centering \
    }
    \fi

    \ifxueweibachelor  % 本科跟硕博很不一样
    \parbox[t][1.0cm][t]{\textwidth}{
      \xiaosan
      \makebox[3.0cm][c]{}
      \makebox[4.0cm][l]{\song 院（系）名~~~~称：}  % 这里用 l 比用 s 效果好，扉页则不是，奇怪
      \makebox[7cm][l]{\song \@caffil}
    }
    \parbox[t][1.0cm][t]{\textwidth}{
      \xiaosan
      \makebox[3.0cm][c]{}
      \makebox[4.0cm][l]{\song 专~~~~业~~~~名~~~~称：}
      \makebox[7cm][l]{\song \@csubject}

    }
    \parbox[t][1.0cm][t]{\textwidth}{
      \xiaosan
      \makebox[3.0cm][c]{}
      \makebox[4.0cm][l]{\song 学~~~~生~~~~姓~~~~名：}
      \makebox[7cm][l]{\song \@cauthor}
    }
    \parbox[t][1.0cm][t]{\textwidth}{
      \xiaosan
      \makebox[3.0cm][c]{}
      \makebox[4.0cm][l]{\song 指~~~~导~~~~教~~~~师：}
      \makebox[7cm][l]{\song \@csupervisor}
    }
    \parbox[t][2.1cm][t]{\textwidth}{
      \begin{center} \end{center}
    }
    \else
    \parbox[t][2.0cm][t]{\textwidth}{
      \xiaoer
      \begin{center} {\song  \@cauthor}  \end{center} }
    \fi

    \ifxueweibachelor
    \else  % TODO: 将来的事
    \parbox[t][8.5cm][t]{\textwidth}{
        \centering
        \includegraphics[width = 8cm]{heu_logo}
    }
    \fi

    \ifxueweibachelor  % 反正本科规范没有这个，硕博未知
    \else
      \parbox[t][1.2cm][t]{\textwidth}{\xiaoer
      \begin{center}{\kai 哈尔滨工程大学}\end{center} }
    \fi

    \parbox[t][0.5cm][t]{\textwidth}{
    \begin{center}{\song \xiaoer \@cdate} \end{center} }

    \end{center}

    % 封二 如果 twoside，空白页
    \ifoneortwoside
      \newpage
      ~~~\vspace{1em}
      \thispagestyle{empty}
    \fi

    % 本科论文扉页
    \newpage
    \thispagestyle{empty}
    \begin{center}

    \parbox[t][0.8cm][t]{\textwidth}{
      \begin{center} \end{center}
    }

    \parbox[t][1cm][b]{\textwidth}{
      \erhao
      \begin{center}{\song 哈尔滨工程大学\cxuewei 毕业论文}\end{center}
    }

    \parbox[t][1.1cm][t]{\textwidth}{
      \begin{center} \end{center}
    }

    \parbox[t][2cm][t]{\textwidth}{
      \xiaoyi
      \begin{center}{\hei \@ctitle}\end{center}
    }

    \parbox[t][4.3cm][t]{\textwidth}{
       \centering \
    }

    \parbox[t][1.0cm][t]{\textwidth}{
      \sihao
      \makebox[3.6cm][c]{}
      \makebox[3.1cm][s]{\song 院~~~~~~~~（系）：}
      \makebox[7cm][l]{\song \@caffil}
    }
    \parbox[t][1.0cm][t]{\textwidth}{
      \sihao
      \makebox[3.6cm][c]{}
      \makebox[3.1cm][s]{\song 专~~~~~~~~~~~~~~业：}
      \makebox[7cm][l]{\song \@csubject}
    }
    \parbox[t][1.0cm][t]{\textwidth}{
      \sihao
      \makebox[3.6cm][c]{}
      \makebox[3.1cm][s]{\song 学~~~~~~~~~~~~~~号：}
      \makebox[7cm][l]{\song \xuehao}
    }
    \parbox[t][1.0cm][t]{\textwidth}{
      \sihao
      \makebox[3.6cm][c]{}
      \makebox[3.1cm][s]{\song 学~~生~~姓~~名：}
      \makebox[7cm][l]{\song \@cauthor}
    }
    \parbox[t][1.0cm][t]{\textwidth}{
      \sihao
      \makebox[3.6cm][c]{}
      \makebox[3.1cm][s]{\song 指~~导~~教~~师：}
      \makebox[7cm][l]{\song \@csupervisor}
    }

    \parbox[t][2.6cm][t]{\textwidth}{
      \begin{center} \end{center}
    }

    \parbox[t][0.5cm][t]{\textwidth}{
    \begin{center}{\song \xiaoer \@cdate} \end{center} }

    \end{center}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  差异太大，故全部注释掉：TODO:将来用 ifx 解决
%  下面是原硕博论文的封面，双 % 的两行是原来就注释过一次的
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \begin{center}
%    \parbox[t][0.6cm][t]{\textwidth}{
%    \begin{center} \end{center}}

%%    \parbox[t][2.2cm][t]{\textwidth}{
%%    \song \xiaosi 国内图书分类号： \@natclassifiedindex \\
%                  国际图书分类号： \@internatclassifiedindex }
%			\parbox[t][2.2cm][t]{\textwidth}{\song \xiaosi \centering 
%			\begin{tabular}{>{\raggedleft}p{4cm}>{\raggedright}p{3.5cm}>{\raggedleft}p{3.5cm}>{\raggedright}p{2cm}}%% %% {rlrl}
%			国内图书分类号：& \@natclassifiedindex  & 学校代码：& 10213 \tabularnewline 
% 			国际图书分类号：& \@internatclassifiedindex &  ~~ 密级：&  公开 
%			\end{tabular}}

%    \parbox[t][2.7cm][b]{\textwidth}{\xiaoer
%    \begin{center} {\song  \@cdegree 学位论文 }\end{center} }

%    \setlength{\baselineskip}{1.5\baselineskip}
%    \parbox[t][3.0cm][b]{\textwidth}{\erhao
%    \begin{center} {\hei  \@ctitle}\end{center} }

%    \parbox[t][4.3cm][t]{\textwidth}{
%    \begin{center}  \end{center} }

%    \parbox[t][6cm][c]{\textwidth}{ {\sihao
%    \begin{center} \renewcommand{\arraystretch}{1.5} \song 
%    \begin{tabular}{lll@{\extracolsep{0em}}l}
%    ~ & {\hei \xueweishort \hfill 士\hfill 研究生：}           & \@cauthor\\
%    ~ & {\hei 导\hfill 师：}                       & \@csupervisor\\
%    \@ccosupervisor
%    \@cassosupervisor
%    ~ & {\hei 申\hfill 请\hspace{1em}学\hfill 位：} & \@cdegree\\
%    ~ & {\hei 学\hfill 科：}           & \@csubject\\
%    ~ & {\hei 所\hfill 在\hspace{1em}单\hfill 位：} & \@caffil\\
%    ~ & {\hei 答\hfill 辩\hspace{1em}日\hfill 期：} & \@cdate\\
%    ~ & {\hei 授予学位单位：}                     & 哈尔滨工业大学
%    \end{tabular} \renewcommand{\arraystretch}{1}
%    \end{center} } }
%\end{center}

%%%%%%增加一空白页
  \ifoneortwoside
    \newpage
    ~~~\vspace{1em}
    \thispagestyle{empty}
  \fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  本科木有英文封面，也全部注释掉：TODO: 将来用 ifx 解决
%  下面是原硕博论文的封面，双 % 的两行是原来就注释过一次的
%  而且没有注释掉时产生的英文封面很难看，因为调整的东西太多了
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \newpage
%    \thispagestyle{empty}
%    \begin{center}
%    \parbox[t][0.6cm][t]{\textwidth}{
%    \begin{center} \end{center}}
%
%    \parbox[t][2.2cm][t]{\textwidth}{
%    \xiaosi Classified Index: \@natclassifiedindex \\
%                  U.D.C.:  \@internatclassifiedindex }
%
%    \parbox[t][2.7cm][b]{\textwidth}{\xiaoer
%    \begin{center} {  Dissertation for the {\exueweier} Degree }\end{center} } %与中文保持一致，删除in {\exueke}
%
%    \parbox[t][3.0cm][b]{\textwidth}{\erhao
%    \begin{center} {  \@etitle}\end{center} }
%
%    \parbox[t][4.0cm][t]{\textwidth}{
%    \begin{center}  \end{center} }
%
%    \parbox[t][6cm][c]{\textwidth}{ {\sihao
%    \begin{center} \renewcommand{\arraystretch}{1.5} 
%    \begin{tabular}{p{0cm}p{14em}p{13.4em}l@{\extracolsep{2em}}l}
%    ~ & \textbf{Candidate:}                     &  \@eauthor\\
%    ~ & \textbf{Supervisor:}                    &  \@esupervisor\\
%    \@ecosupervisor
%    \@eassosupervisor
%    ~ & \textbf{Academic Degree Applied for:}   &  \@edegree\\
%    ~ & \textbf{Specialty:}                     &  \@esubject\\
%    ~ & \textbf{Affiliation:}                   &  \@eaffil\\
%    ~ & \textbf{Date of Defence:}               &  \@edate\\
%    ~ & \textbf{Degree-Conferring-Institution:} &  Harbin Institute of Technology
%    \end{tabular}
%    \end{center}}}
%
%    \end{center}

    \end{titlepage}

%%%%%%增加一空白页
  \ifoneortwoside
    \newpage
    ~~~\vspace{1em}
    \thispagestyle{empty}
  \fi
%%%%%%%%%%%%%%%%%%%   Abstract and keywords  %%%%%%%%%%%%%%%%%%%%%%%
%\clearpage \BiAppendixChapter{摘~~~~~~~~要}{Abstract (in Chinese)}  % 不要挪到下一行，生成正确的摘要toc；如果需要把摘要加入目录，请照上面那句话来
% TODO: 由于哈工程本科论文规范规定摘要不能加入目录，所以进行了手工设置，采用最笨的方法，修改 \BiAppendixChapter (set/Definition.tex) 命令，制作新的命令 \BiAppendixChapterTMP，将 toc 改为 toe，反正不用英文目录，问题暂时解决，将来仔细研究研究，会有更好的办法
\clearpage \BiAppendixChapterTMP{摘~~~~~~~~要}{Abstract (in Chinese)}
\setcounter{page}{1}
\song \normalsize
\defaultfont
\@cabstract
\vspace{1.6em}

\hangafter1\hangindent4.28em\noindent
{\hei 关键词：} \@ckeywords

%%%%%%%%%%%%%%%%%%%   English Abstract  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
%\defaultfont \BiAppendixChapter{\textbf{ABSTRACT}}{Abstract (in English)}  % 不要挪到下一行，生成正确的摘要toc
\defaultfont \BiAppendixChapterTMP{\textbf{ABSTRACT}}{Abstract (in English)}  % TODO:同上面中文摘要
\@eabstract
\vspace{1.6em}

\hangafter1\hangindent5.5em\noindent
{\textbf{Key words:}}  \@ekeywords
\wuhaobiao  % 正文表格设置
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  英文目录格式
%  本科暂时没有，未修改
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\@dotsep{1}           % 定义英文目录的点间距
\setlength\leftmargini {0pt}
\setlength\leftmarginii {0pt}
\setlength\leftmarginiii {0pt}
\setlength\leftmarginiv {0pt}
\setlength\leftmarginv {0pt}
\setlength\leftmarginvi {0pt}

\def\engcontentsname{\bfseries Contents}
\newcommand\tableofengcontents{%
   %\cleardoublepage
   \pdfbookmark[0]{Contents}{econtent}
   \if@twocolumn
     \@restonecoltrue\onecolumn
   \else
     \@restonecolfalse
   \fi   \chapter*{\engcontentsname  %chapter*上移一行，避免在toc中出现。
       \@mkboth{%
          \engcontentsname}{\engcontentsname}}
   \@starttoc{toe}%
   \if@restonecol\twocolumn\fi
}

\urlstyle{same}  % 论文中引用的网址的字体默认与正文中字体不一致，这里修正为一致的。

% 主要符号表 \NotationList TODO: 暂时用不上这个，未修改
\long\def\notation{\clearpage \BiAppendixChapter{主要符号表}{Main Symbol Table}\normalbiao\@NotationList\wuhaobiao}

%%% 五号字表格设置 start %%%%%  TODO: 哈工程本科表格小四号，需要重新定义小四号表 \xiaosihaobiao
\gdef\tpltable{\relax}
\let\tpltable\longtable
\gdef\wuhaobiao{%五号字
    \def\tabular{\wuhao\gdef\@halignto{}\@tabular}
    \def\endtabular{\endarray $\egroup}
    \def\longtable{\wuhao\tpltable}
    \def\endlongtable{\adl@LTlastrow \adl@org@endlongtable}
}
\gdef\normalbiao{%正常字号
    \def\tabular{\gdef\@halignto{}\@tabular}
    \def\endtabular{\endarray $\egroup}
    \def\longtable{\tpltable}
    \def\endlongtable{\adl@LTlastrow \adl@org@endlongtable}
}
\wuhaobiao
%%% 五号字表格设置 end %%%%%
%\renewcommand{\arraystretch}{1.4} %表格中行距 ，导致公式 bmatrix 间距增大。

% 表格与下方间距 TODO: 将来根据实际情况调节
\renewcommand\endtable{\vspace{-4mm}\end@float}

% 算法与下方间距
%\renewcommand\endalgorithm{\@algocf@finish \ifthenelse {\equal {\algocf@float }{figure}}{\end {figure}}{
%\@algocf@term@caption \ifthenelse {\boolean {algocf@algoH}}{\end {algocf@Here}}
%{\end {algocf}}}\@algocf@term\vspace{-5mm}}
% algorithm2e的4.0版本删除了\endalgorithm的命令，改为直接定义algoco@algorithm环境的形式，造成使用上面的语句为出现错误：
% Latex Error:\begin{algoco@algorithm} on input line 526 ended by \end{algorithm}  
\makeatother
